package shiro.com.utils.shiro;


import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import shiro.com.domain.sys.SysUsers;
import shiro.com.service.sys.ISysUsersService;
import shiro.com.utils.shiro.token.JwtToken;
import shiro.com.utils.shiro.util.StringUtil;

/**
 * 解密器
 */
@Component
public class MyCredentialsMatcher  extends SimpleCredentialsMatcher {
    @Autowired
    private ISysUsersService userService;
    @Override
    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
        JwtToken jwtToken = (JwtToken)token;
        if (jwtToken.getPassword() == null) {
            return true;
        }
        String inPassword = new String(jwtToken.getPassword());
        String username = String.valueOf(info.getPrincipals());
        String dbPassword = (String) info.getCredentials();
        SysUsers user = userService.selectByUsername(username);
        String salt = user.getSysUserSlat();
       // return this.equals(StringUtil.md5(inPassword + salt),dbPassword);
        return inPassword.equals(dbPassword);
    }
}
